<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>常量管理</title>
<script type="text/javascript" src="<c:url value='/admin/js/util/jquery-1.8.1.min.js' />" ></script>
<script type="text/javascript" src="<c:url value='/admin/js/util/page.js' />" ></script>
<script type="text/javascript" src="<c:url value='/admin/js/util/common.js' />" ></script>
<script type="text/javascript" src="<c:url value='/admin/js/util/validate.js' />" ></script>
<link href="<c:url value='/admin/css/general.css'/>" rel="stylesheet" type="text/css" />
<script language="javascript">
	function senfe(o, a, b, c) {
		var t = document.getElementById(o).getElementsByTagName("tr");
		for ( var i = 0; i < t.length; i++) {
			t[i].style.backgroundColor = (t[i].sectionRowIndex % 2 == 0) ? a
					: b;
			t[i].onmouseover = function() {
				if (this.x != "1")
					this.style.backgroundColor = c;
			};
			t[i].onmouseout = function() {
				if (this.x != "1")
					this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a
							: b;
			};
		}
	}

	function addCustomers(o, a, b) {
		var t = document.getElementById(o).getElementsByTagName("tr");
		for ( var i = 0; i < t.length; i++) {
			t[i].style.backgroundColor = (t[i].sectionRowIndex % 2 == 0) ? a
					: b;
			t[i].onmouseout = function() {
				if (this.x != "1")
					this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a
							: b;
			};
		}
	}
		
	function queryList() {
		$("#mainForm").attr("action", "<c:url value='/admin/frameConstantAction!modify.do' />");
		$("#mainForm").submit();
	}
	
	function queryRadioList(constantId) {
		$("#constantId_modify").val(constantId);
		$("#mainForm").attr("action", "<c:url value='/admin/frameConstantAction!modify.do' />");
		$("#mainForm").submit();
	}

	function list(currentPageNO) {
		$("#currentPageNO").val(currentPageNO);
		$("#mainForm").attr("action", "<c:url value='/admin/frameConstantAction!modify.do' />");
		$("#mainForm").submit();
	}

	function prePage(currentPageNO) {
		var prePageNO = getPrePageNO(currentPageNO);
		list(prePageNO);
	}

	function nextPage(currentPageNO) {
		var totalPage = "${ page.totalPage }";
		var nextPageNO = getNextPageNO(currentPageNO, totalPage);
		list(nextPageNO);
	}

	function goPage() {
		if(!isInteger("inputPageNo","请输入正确的页号！")) {
			return;
		}
		var inputPageNO = $("#inputPageNo").val();
		var totalPage = "${ page.totalPage }";
		if ((parseInt(inputPageNO) < 1) || (parseInt(inputPageNO) > parseInt(totalPage))) {
			alert("数据不存在！");
			return;
		}
		list(inputPageNO);
	}
	
	function editObj() {
		if (validate()) {
			$("#mainForm").attr("action", "<c:url value='/admin/frameConstantAction!modifyExc.do' />");
			$("#mainForm").submit();
		}
	}
	
	function deleteObj() {
		if ($("#constantId_self").val() == "") {
			alert("请选中需要删除的项！");
			return;
		}
		if (confirm('确定删除吗？')) {
			$("#mainForm").attr("action", "<c:url value='/admin/frameConstantAction!delete.do' />");
			$("#mainForm").submit();
		}
	}
	
	function addObj() {
		$("#constantId").val("");
		$("#constantValue").val("");
		$("#constantName").val("");
	}
	
	function validate() {
		if (!validateLength("constantValue",1,40,"请输入常量值！","请输入短一点的常量值！"))
			return false;
		if (!validateLength("constantName",1,80,"请输入常量备注！","请输入短一点的常量备注！"))
			return false;
		return true;
	}
</script>
</head>
<body>
	<form id="mainForm" action="" method="post">
		<input type="hidden" name="pageSize" id="pageSize" value="" />
		<input type="hidden" name="sectionSize" id="sectionSize" value="" />
		<input type="hidden" name="currentPageNO" id="currentPageNO" value="${ page.currentPageNO }" />
		<input type="hidden" name="constantKey" id="constantKey" value="${ requestScope.constantKey }" />
		<input type="hidden" name="constantId_modify" id="constantId_modify" value="" />
		
		<div class="tableTitle">常量管理</div>
		<div class="soso">
			<span>搜索选项：</span>常量备注：<input name="constantName_find" type="text" value="${ requestScope.constantName_find }"/> <a href="javascript:queryList();">查找</a>
		</div>
		<table width="100%" cellspacing="1" id="senfe">
			<tr>
				<th width="5%">选择</th>
				<th width="10%">常量名称</th>
				<th width="10%">常量值</th>
				<th width="75%">常量备注</th>
			</tr>
			<c:forEach var="item" items="${ constantList }" varStatus="status">
				<tr>
					<td><input name="constant_radio" type="radio" value="${ item.id }" onclick="queryRadioList('${ item.id }')"/></td>
					<td>${ item.moduleName }</td>
					<td>${ item.constantValue }</td>
					<td>${ item.constantName }</td>
				</tr>
			</c:forEach>
			<tr>
				<td colspan="4">
					<table>
						<tr>
							<td>共有 ${ page.totalRecordSize } 条记录，当前第 ${ page.currentPageNO }/${ page.totalPage } 页</td>
							<td class="tdRight"><a href="javascript:list(1);">首页</a> <a href="javascript:prePage(${ page.currentPageNO });">上一页</a> <a
								href="javascript:nextPage(${ page.currentPageNO });">下一页</a> <a href="javascript:list(${ page.totalPage });">末页</a> 转到第<input id="inputPageNo" type="text" />页
								<a href="javascript:goPage();">GO</a></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<script language="javascript">
			//senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景"); 
			senfe("senfe", "#fff", "#F6F6F6", "#E1F2F9");
		</script>
		<br />
		<table width="100%" cellspacing="1" id="addCustomers">
			<tr>
				<th>注：带<b>*</b>号的为必填项
				</th>
			</tr>
			<tr>
				<td><span>常量值<b>*</b>：
				</span>
				<input type="hidden" name="frameConstant.id" id="constantId" value="${ frameConstant_modify.id }" />
				<input type="hidden" name="frameConstant.moduleName" id="constantModuleName" value="${ frameConstant_modify.moduleName }" />
				<input name="frameConstant.constantValue" id="constantValue" type="text" value="${ frameConstant_modify.constantValue }" maxlength="40"/></td>
			</tr>
			<tr>
				<td><span>常量备注<b>*</b>：
				</span><textarea name="frameConstant.constantName" id="constantName" cols="" rows="">${ frameConstant_modify.constantName }</textarea></td>
			</tr>
			<tr>
				<td><a href="javascript:addObj();">新增</a><a href="javascript:editObj();">保存</a><a href="javascript:deleteObj();">删除</a></td>
			</tr>
		</table>
	</form>
	<script language="javascript">
		//addCustomers("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景"); 
		addCustomers("addCustomers", "#fff", "#F6F6F6");
		
		selectRadio("constant_radio", "${ frameConstant_modify.id }");
	</script>
</body>
</html>
